<?php
class Zenddn_Controller_Action extends Zend_Controller_Action{
    
    protected $_templateURL;
    
    public function init(){
        //$this->redirectHttps();
        $this->loadTemplate();
    }
    
    protected function loadTemplate($layout = "system"){
        $module = $this->_request->getParam('module');
        $this->_helper->layout->setLayoutPath(realpath(TEMPLATE_PATH . '/' . $module . '/' . $layout));
        $templatePath = $this->view->baseURL() . '/templates/' . $module . '/' . $layout;
        
        $this->view->templateURL = $templatePath;
        $this->_templateURL = $templatePath;
        
        //=====Real Hosting
        /*$module = $this->_request->getParam('module');
        $this->_helper->layout->setLayoutPath(realpath(TEMPLATE_PATH . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . $layout));
        $templatePath = $this->view->serverUrl() . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR  . $module . DIRECTORY_SEPARATOR  . $layout;
        $this->view->templateURL = $templatePath;
        $this->_templateURL = $templatePath;*/
    }
    
    protected function addScripts($scripts = array()){
        foreach($scripts as $script){
            $this->view->headScript()->appendFile($this->_templateURL . "/js/" . $script);
        }
    }
    
    protected function addCustomeScript($script){
        $this->view->headScript()->appendFile($script);
    }
    
    protected function addStyleSheet($styles = array(), $customPath = false){
        foreach($styles as $style){
            $this->view->headLink()->appendStylesheet($this->_templateURL . "/css/" . $style);
        }
    }
    
    protected function addCustomeStyleSheet($style){
        $this->view->headLink()->appendStylesheet($style);
    }
    
    public function redirectHttps(){
    	if (!isset($_SERVER['HTTPS']) && !($_SERVER['HTTPS'])) {
            $request    = $this->getRequest();
            $url        = 'https://'
                        . $_SERVER['HTTP_HOST']
                        . $request->getRequestUri();
            $redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
            $redirector->gotoUrl($url);
        } 
    }
    
    /*public function createBreadcrumb($controller, $titleCurrentAction = null, $indexAction = 'index', $titleIndexAction = 'index'){
        $urlIndexAction = array('module' => 'admin', 'controller' => $controller, 'action' => $indexAction);
        $breadcrumb = array();
    	$breadcrumb[] = array('title' => $titleIndexAction, 'url' => $urlIndexAction);
        
        if($titleCurrentAction != null){
            $breadcrumb[] = array('title' => $titleCurrentAction, 'url' => null);
        }
        
        return $breadcrumb;
    }*/
}